<script src = "https://cdn.wilddog.com/sdk/js/2.5.17/wilddog-sync.js"></script>
<script>
    var wilddogurl="{$cfg['wilddog']}";
    var oldTimestime=0;
    if(wilddogurl.length>10){
        var wilddogconfig = {
            syncURL: "{$cfg['wilddog']}"
        };
        wilddog.initializeApp(wilddogconfig);
        var ref = wilddog.sync().ref("/shopid/{php echo $shopid}");
        var connectedRef = wilddog.sync().ref("/.info/connected");
        connectedRef.on("value", function(snap) {
            if (snap.val() === true) {
                console.log("连接成功");
            } else {
                console.log("离线，重新连接");
                setTimeout(function(){
                    wilddog.sync().goOnline();
                },2000);
            }
        });
        ref.on("value", function(snapshot) {
            if(snapshot.val()==null){
                var refroot = wilddog.sync().ref("/shopid/{php echo $shopid}");
                refroot.set({
                    "{php echo $shopid}":"done"
                });
            }else{
                var wildval=snapshot.val();
                console.log(wildval);
                var timetemp=parseInt(wildval["{php echo $shopid}"]);
                if(timetemp>oldTimestime){
                    console.log("收到数据："+timetemp);
                    oldTimestime=timetemp;
                    if($(".page_table").is(":visible")){
                        console.log("刷新"+$(".pt_menubar .isselect").find('a').text());
                        $(".pt_menubar .isselect").find('a').click();
                    }
                }
            }
        });
    }
</script>